package servlet;


import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class FormServlet extends HttpServlet {
	@Override
	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		//post方法处理乱码
		request.setCharacterEncoding("utf8");
		//输出不乱码charset=utf8
		response.setContentType("text/html;charset=utf8");
		PrintWriter out = response.getWriter();
		//username=ab&password=123&drink=1&drink=2
		String un = request.getParameter("username");
		//get方式，解决乱码
		//pwd可能是null
		String pwd= request.getParameter("password");
		//drinks可能是null
		String[] drinks=request.getParameterValues("drink");
		out.println(un);
		out.println(pwd);
		out.println(Arrays.toString(drinks));
		
	}
	
}
